import { createStore } from 'vuex'

export default createStore({
  state: {
    query:'',
    searchHistory:[]
  },
  mutations: {
    changeQuery(state,val){
      state.query = val
    },
    clearQuery(state){
      state.query = ""
    },
    addSearchHistory(state,val){
      state.searchHistory.push(val)
    },
    clearSearchHistory(state){
      state.searchHistory = []
    }
  },
  actions: {
    changeQuery({commit},val){
      commit('changeQuery',val)
    },
    clearQuery({commit},){
      commit('clearQuery')
    },
    addSearchHistory({commit},val){
      commit('addSearchHistory',val)
    },
    clearSearchHistory({commit}){
      commit('clearSearchHistory')
    }
  },
  getters: {
    getQuery:(state) => {
      return state.query
    }
  },
  modules: {
  }
})
